<?php

namespace App\Http\Controllers\Backend;
use App\Common\ResponseCode;
use App\Http\Controllers\BaseController;
use App\Http\Middleware\AdminAuth;
use App\Params\Backend\ResourceListParam;
use App\Params\Backend\ResourceUpdateParam;
use App\Params\Backend\UserListParam;
use App\Params\Backend\UserUpdateParam;
use App\Services\Base\ResourceService;
use App\Services\User\UserService;
use App\Traits\VerifyRequestParam;
use Illuminate\Http\Request;
/**
 * 系统资源控制器
 *
 * @package App\Http\Controllers\H5
 * @author WangBin
 * @date 2021-06/11
 */
class ResourcesController extends BaseController
{
    use VerifyRequestParam;

    public function __construct()
    {
        $this->middleware(AdminAuth::class);
    }

    /**
     * 系统资源列表
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function getList()
    {
        $param = ResourceListParam::create();
        $ret = ResourceService::getInstance()->getList($param);
        return $this->success($ret);
    }

    /**
     * 保存资源
     *
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\BusinessException
     */
    public function update()
    {
        $param = ResourceUpdateParam::create();
        $ret = ResourceService::getInstance()->update($param);
        if($ret) {
            return $this->success();
        }
        return $this->fail(ResponseCode::RESOURCE_UPDATE_FAIL);
    }

    /**
     * 获取资源
     *
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\BusinessException
     */
    public function get()
    {
        $ret = ResourceService::getInstance()->get($this->verifyInteger('resource_id'));
        return $this->success($ret);
    }

    /**
     * 禁用/启用资源
     *
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\BusinessException
     */
    public function enable()
    {
        $ret = ResourceService::getInstance()->enable($this->verifyInteger('resource_id'));
        return $this->success();
    }
}
